<template>
	<view class="page">
		<view class="header">
			<view class="title">我的足迹</view>
			<view class="delete-btn" @click="showDeleteConfirm">
				<image class="delete-icon" src="/static/svg/delete-footprint.svg" mode="aspectFit"></image>
				<text class="delete-text">删除</text>
			</view>
		</view>
		
		<view v-if="footprintList.length > 0" class="footprint-list">
			<view v-for="(item, index) in footprintList" :key="index" class="footprint-item">
				<view class="product-card" @click="navigateToProduct(item.id)">
					<image class="product-image" :src="item.image" mode="aspectFill"></image>
					<view class="group-tag" v-if="item.isGroup">{{item.groupCount}}人团</view>
					<view class="product-info">
						<view class="product-name">{{item.name}}</view>
						<view class="product-sold">已售 {{item.soldCount}}件</view>
						<view class="product-price">¥{{item.price}}</view>
						<view class="btn-row">
							<view class="delete-item-btn" @click.stop="deleteItem(index)">删除足迹</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<view v-else class="empty-state">
			<image class="empty-icon" src="/static/svg/footprint.svg" mode="aspectFit"></image>
			<view class="empty-text">您还没有浏览过任何商品</view>
		</view>
		
		<uni-popup ref="deletePopup" type="dialog">
			<uni-popup-dialog 
				type="warning" 
				cancelText="取消" 
				confirmText="确认" 
				title="删除确认" 
				content="确定要删除所有足迹记录吗？" 
				@confirm="deleteAllFootprints" 
				@close="closePopup"
			></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { onPullDownRefresh } from '@dcloudio/uni-app';

// 设置下拉刷新
onPullDownRefresh(() => {
	refreshData();
});

// 模拟足迹数据
const footprintList = ref([
	{
		id: 1,
		name: '艾丽莎抹茶蛋糕早点低糖健康',
		image: '/static/svg/matcha-cake.svg',
		price: 136,
		soldCount: 536,
		isGroup: true,
		groupCount: 3
	},
	{
		id: 2,
		name: '法式千层蛋糕',
		image: '/static/svg/crepe-cake.svg',
		price: 128,
		soldCount: 423,
		isGroup: false
	},
	{
		id: 3,
		name: '黑森林蛋糕',
		image: '/static/svg/black-forest.svg',
		price: 168,
		soldCount: 312,
		isGroup: true,
		groupCount: 5
	},
	{
		id: 4,
		name: '草莓奶油蛋糕',
		image: '/static/svg/strawberry-cake.svg',
		price: 148,
		soldCount: 256,
		isGroup: false
	},
	{
		id: 5,
		name: '榴莲千层蛋糕',
		image: '/static/svg/durian-cake.svg',
		price: 158,
		soldCount: 198,
		isGroup: true,
		groupCount: 3
	}
]);

const deletePopup = ref(null);

function showDeleteConfirm() {
	deletePopup.value.open();
}

function closePopup() {
	deletePopup.value.close();
}

function deleteAllFootprints() {
	footprintList.value = [];
}

function deleteItem(index) {
	footprintList.value.splice(index, 1);
}

function navigateToProduct(id) {
	uni.navigateTo({
		url: `/pages/index/product?id=${id}`
	});
}

// 刷新数据
function refreshData() {
	// 这里模拟刷新数据
	setTimeout(() => {
		// 停止下拉刷新动画
		uni.stopPullDownRefresh();
	}, 1000);
}

// 页面加载完成
onMounted(() => {
	// 初始化数据
});
</script>

<style>
	.page {
		width: 100vw;
		min-height: 100vh;
		background-color: #f7f7f7;
		padding-bottom: 30rpx;
	}
	
	.header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx;
		background-color: #ffffff;
	}
	
	.title {
		font-size: 36rpx;
		font-weight: bold;
		color: #333;
	}
	
	.delete-btn {
		display: flex;
		align-items: center;
	}
	
	.delete-icon {
		width: 40rpx;
		height: 40rpx;
		margin-right: 6rpx;
	}
	
	.delete-text {
		font-size: 28rpx;
		color: #FF5722;
	}
	
	.footprint-list {
		width: 100%;
		padding: 20rpx;
	}
	
	.footprint-item {
		margin-bottom: 20rpx;
	}
	
	.product-card {
		width: 100%;
		height: 240rpx;
		display: flex;
		position: relative;
		background-color: #fff;
		border-radius: 12rpx;
		box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
		overflow: hidden;
		margin-bottom: 0; /* 消除底部多余间距 */
	}
	
	.product-image {
		width: 240rpx;
		height: 240rpx;
		object-fit: cover;
	}
	
	.group-tag {
		position: absolute;
		top: 20rpx;
		left: 0;
		background-color: #ff6a3c;
		color: #fff;
		font-size: 24rpx;
		padding: 6rpx 12rpx;
		border-radius: 0 8rpx 8rpx 0;
	}
	
	.product-info {
		flex: 1;
		padding: 20rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}
	
	.product-name {
		font-size: 32rpx;
		font-weight: 500;
		color: #333;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}
	
	.product-sold {
		font-size: 26rpx;
		color: #999;
		margin-top: 10rpx;
	}
	
	.product-price {
		font-size: 36rpx;
		color: #ff6a3c;
		font-weight: bold;
		margin-top: 10rpx;
	}
	
	.btn-row {
		display: flex;
		justify-content: flex-end;
		margin-top: 10rpx;
	}
	
	.delete-item-btn {
		padding: 8rpx 20rpx;
		font-size: 24rpx;
		color: #666;
		border: 1px solid #ddd;
		border-radius: 30rpx;
	}
	
	.empty-state {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 100rpx 0;
	}
	
	.empty-icon {
		width: 160rpx;
		height: 160rpx;
		margin-bottom: 30rpx;
	}
	
	.empty-text {
		font-size: 28rpx;
		color: #999;
	}
</style>
